//
//  DetailViewController.swift
//  issac-note
//
//  Created by Issac on 16/8/21.
//  Copyright © 2016年 Issac. All rights reserved.
//

import UIKit

class DetailViewController: UIViewController, UITextFieldDelegate, UITextViewDelegate {
    
    @IBOutlet var titleText: UITextField!
    @IBOutlet var contentText: UITextView!
    @IBOutlet var navRightBtn: UIBarButtonItem!
    @IBOutlet var cttToolBar: UIToolbar!
    
    var indexPath: Int?

    override func viewDidLoad() {
        super.viewDidLoad()
        
        self.titleText.delegate = self
        self.contentText.delegate = self
        
        self.titleText.text = "这是标题" + String(self.indexPath!)
        self.contentText.text = "这是内容" + String(self.indexPath!)
        
        self.titleText.layer.borderWidth = 1
        self.titleText.layer.borderColor = UIColor.init(red: 229/255, green: 229/255, blue: 229/255, alpha: 1).CGColor
        self.titleText.layer.cornerRadius = 3
        
        self.cttToolBar.layer.borderWidth = 1
        self.cttToolBar.layer.borderColor = UIColor.init(red: 229/255, green: 229/255, blue: 229/255, alpha: 1).CGColor
        
        self.contentText.layer.borderWidth=1
        self.contentText.layer.borderColor = UIColor.init(red: 229/255, green: 229/255, blue: 229/255, alpha: 1).CGColor
        self.contentText.layer.cornerRadius = 5
        
        
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    
    //标题重新分配第一响应者
    func textFieldShouldReturn(textField: UITextField) -> Bool {
        
        textField.resignFirstResponder()
        
        return true
        
    }
    
    //开始编辑内容触发的事件
    func textViewDidBeginEditing(textView: UITextView) {
        
        self.navRightBtn.title = "完成"
        
    }
    
    //导航栏右按钮事件
    @IBAction func textViewEditingEnd(sender: UIBarButtonItem) {
        
        if(sender.title == " "){
        
            print("nil")
            
        }else {
        
            self.contentText.resignFirstResponder()
            self.titleText.resignFirstResponder()
            sender.title = " "
            
        }
        
    }

    /*
    // MARK: - Navigation

    // In a storyboard-based application, you will often want to do a little preparation before navigation
    override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
        // Get the new view controller using segue.destinationViewController.
        // Pass the selected object to the new view controller.
    }
    */

}
